import 'dart:async';
import 'package:isolate/isolate.dart';

final Future<LoadBalancer> loadBalancerCreator = LoadBalancer.create(3, IsolateRunner.spawn);

late final LoadBalancer lb;

Future<void> initializeLoadBalancer() async {
  lb = await loadBalancerCreator;
}

Future<R> performSelector<R, P>(
  FutureOr<R> Function(P) function,
  P argument,
) async {
  final res = await lb.run<R, P>(function, argument);
  return res;
}

class LYIsolateManager {
  static Future<R> performSelector<R, P>(
    FutureOr<R> Function(P) function,
    P argument,
  ) async {
    final res = await lb.run<R, P>(function, argument);
    return res;
  }
}
